import Vue from 'vue'
import Vuex from 'vuex'
import state from "./state.js"
Vue.use(Vuex);//vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
    state:state,
	mutations:{
		add(state,id){
			console.log(123335555)
			let list = state.list;
			if (list.length > 0) {
				let test = list.some(item => {
					return item.id == id;
				});
				if (test) {
					let index = 0;
					for(let i = 0; i < list.length; i++){
						console.log(i);
						if(list[i].id == id){
							index = i;
						}
					}
					state.list[index].num +=1;
				} else {
					console.log(5563)
					list.push({
						id: id,
						num: 1,
						price: 30,
						goodsImage: "https://img0.baidu.com/it/u=393085392,746235864&fm=26&fmt=auto&gp=0.jpg",
						is_check: false,
					});
					state.list = list;
				}
			}
		}
	}
})
export default store